﻿#region

using System.Web.Mvc;
using CuongHanh.Context;
using CuongHanh.Models;
using CuongHanh.Models.Filter;
using CuongHanh.Service;
using Ext.Net.MVC;

#endregion

namespace CuongHanh.Controllers.BO
{
    public class ServiceFeeController : ABaseController
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult ShowAdd(string containerId)
        {
            return ShowWindow("Add",
                    containerId,
                    new ServiceFee());
        }

        [HttpPost]
        public ActionResult Add(ServiceFee model)
        {
            ServiceFee newModel = new ServiceFee(model);
            UpdateResult result = ShippingCostService.Insert(newModel);
            ShowWindow("wdModify",
                    false);
            ReloadStore("storeGvData");
            ShowNotification(result);
            return this.Direct();
        }

        public ActionResult Command(string containerId,
                string command,
                int id)
        {
            if(command == "Delete")
            {
                UpdateResult result = ShippingCostService.Delete(id);
                ReloadStore("storeGvData");
                ShowNotification(result);
            }
            if(command == "Edit")
            {
                ServiceFee model = ShippingCostService.Find(id);
                return ShowWindow("Edit",
                        containerId,
                        model);
            }
            return this.Direct();
        }

        [HttpPost]
        public ActionResult Edit(ServiceFee model)
        {
            UpdateResult result = ShippingCostService.Update(model);
            ShowWindow("wdModify",
                    false);
            ReloadStore("storeGvData");
            ShowNotification(result);
            return this.Direct();
        }

        public ActionResult GetDatas(int start,
                int limit,
                string filter)
        {
            return Content(ShippingCostService.Gets(start,
                    limit,
                    JsonSerializer.Deserialize<ShippingCostFilter>(filter)),
                    "json");
        }
    }
}
